package com.example.yuejianapp14.Activity.Fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yuejianapp14.Activity.Adapter.ClubInfoAdapter;
import com.example.yuejianapp14.Activity.JavaBean.Club;
import com.example.yuejianapp14.Activity.JavaBean.Coach;
import com.example.yuejianapp14.Activity.Listener.ClubNoListListener;
import com.example.yuejianapp14.Activity.Listener.CoachListener;
import com.example.yuejianapp14.Activity.Model.ClubModel;
import com.example.yuejianapp14.Activity.Model.CoachModel;
import com.example.yuejianapp14.R;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ClubInfoFragment extends Fragment {
    private RecyclerView recyclerView;
    private List mDataList;
    private View view;
    private TextView instruction,address,phone,time;

    public ClubInfoFragment() {
        // Required empty public constructor
    }


    ClubNoListListener<Club> clubInfoListener=new ClubNoListListener<Club>() {
        public void onResponse(Club clubInfo) {
            instruction.setText("俱乐部简介:  "+clubInfo.getInstruction());
            address.setText("俱乐部地址  "+clubInfo.getAddress());
            phone.setText("俱乐部电话  "+clubInfo.getPhone());
            time.setText("营业时间  "+clubInfo.getTime());
        }
        @Override
        public void onFail(String msg) {
           Toast.makeText(getActivity(),"失败",Toast.LENGTH_SHORT).show();
        }
    };


    CoachListener clubcoachListener = new CoachListener() {
        @Override
        public void onResponse(List<Coach> beanList) {
            mDataList=beanList;
            ClubInfoAdapter adapter = new ClubInfoAdapter(getActivity(),mDataList);
            recyclerView.setAdapter(adapter);
        }

        @Override
        public void onFail(String msg) {

        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_club_info, container, false);
        initRecyclerView();
        getData();
        return view;
    }
    private void getData() {
        Intent intent = getActivity().getIntent();
        ClubModel clubModel =new ClubModel();//1
        CoachModel coachModel=new CoachModel();
        clubModel.findClub(intent.getStringExtra("clubid"),clubInfoListener);
        coachModel.findCoach(intent.getStringExtra("clubid"),clubcoachListener);
    }

    private void initRecyclerView() {
        recyclerView = (RecyclerView) view.findViewById(R.id.rv);
        recyclerView.setLayoutManager(new LinearLayoutManager((this.getActivity())));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        instruction= (TextView) view.findViewById(R.id.instruction);
        address= (TextView) view.findViewById(R.id.address);
        phone= (TextView) view.findViewById(R.id.phone);
        time= (TextView) view.findViewById(R.id.time);
    }


}
